using System;
using System.Collections.Generic;
using System.Text;
using UMC.Data;

namespace UMC.WorkFlow.Subassembly
{
    [UMC.WorkFlow.DefaultDesign(ArgumentType = UMC.WorkFlow.ArgumentType.Command, ArgumentValue = "HttpSetting")]
    public class HttpSetting: IJSONType
    {

        protected virtual string JSONName()
        {
            return this.GetType().Name;
        }
        public virtual Func<object> GetInstance(string prototypeName)
        {
            return () => String.Empty;
            //throw new NotImplementedException();
        }

        public virtual void Read(string key, object value)
        {
            switch (key)
            {
                case "Url":
                    this.Url = value as string;
                    break;
                case "Manger":
                    this.Manger = value as string;
                    break;
                case "CommandType":
                    this.CommandType = Utility.Parse(value as string, CommandType.Undefine);
                    break;
            }
        }
        protected virtual void WriteProperty(System.IO.TextWriter writer)
        {
            if (String.IsNullOrEmpty(this.Manger) == false)
            {
                writer.Write(',');
                JSON.Serialize("Manger", this.Manger, writer);
            }
            if (String.IsNullOrEmpty(this.Url) == false)
            {
                writer.Write(',');
                JSON.Serialize("Url", this.Url, writer);
            }
            if (this.CommandType > CommandType.Undefine)
            {
                writer.Write(',');
                JSON.Serialize("CommandType", this.CommandType, writer);
            }
        }

        public void Write(System.IO.TextWriter writer)
        {
            writer.Write('{');
            JSON.Serialize(JSON.Constructor, JSONName(), writer);
            WriteProperty(writer);
            writer.Write('}');
        }
        public UMC.WorkFlow.CommandType CommandType
        {
            get;
            set;
        }
        /// <summary> 
        /// </summary> 
        public string Manger
        {
            get;
            set;
        }
        /// <summary> 
        /// </summary> 
        public string Url
        {
            get;
            set;
        }
    }
}
